//路由器
app.config(function($routeProvider){
    $routeProvider.
    when("/",{
       controller: 'watch_msg',
       templateUrl: 'view/watch_msg.html',
       resolve : {
          async : getJSON(urlAddress + "/json/watch_msg.json")
       }
    }).
    when("/index",{
       controller: 'watch_msg',
       templateUrl: 'view/watch_msg.html',
       resolve : {
          async : getJSON(urlAddress + "/json/watch_msg.json")
       }
    }).
    when("/watch_msg",{
       // 手表信息管理页面
       controller: 'watch_msg',
       templateUrl: 'view/watch_msg.html',
       resolve : {
          async : getJSON(urlAddress + "/json/watch_msg.json")
       }
    }).
    when("/users_sign",{
       // 用户信息管理
       controller: 'users_sign',
       templateUrl: 'view/users_sign.html',
        resolve : {
          async : getJSON(urlAddress + "/json/users_sign.json")
       }
    }).
    when("/users_opi",{
       //用户意见反馈
       controller: 'users_opi',
       templateUrl: 'view/users_opi.html',
       resolve : {
          async : getJSON(urlAddress + "/json/users_opi.json")
       }
    }).
    when("/us_det",{
       // 用户信息编辑
       controller: 'us_det',
       templateUrl: 'view/user_det.html',
       resolve : {
          async : getJSON(urlAddress + "/json/us_det.json")
        }
    }).
    when("/dev_set",{
       // 设备控制页面
       controller: 'dev_set',
       templateUrl: 'view/dev_set.html',
       resolve : {
          async : function() {
                        return 1
                    }
       }
    }).
    when("/dev_position",{
       //设备定位
       controller: 'dev_position',
       templateUrl: 'view/device/dev_position.html',
       resolve : {
          async : getJSON(urlAddress + "/json/dev_set/dev_position.json")
      }
    }).
    when("/move_record",{
       //移动记录
       controller: 'move_record',
       templateUrl: 'view/device/move_record.html',
       resolve : {
          async : getJSON(urlAddress + "/json/dev_set/move_record.json")
      }
    }).
    when("/safe_file",{
       //行动区域划分
       controller: 'safe_file',
       templateUrl: 'view/device/safe_file.html',
       resolve : {
          async : getJSON(urlAddress + "/json/dev_set/safe_file.json")
      }
    }).
    when("/safe_map/:id",{
       //行动区域设置地图
       controller: 'safe_map',
       templateUrl: 'view/device/safe_map.html',
       resolve : {
          async : getJSON(urlAddress + "/json/dev_set/safe_file.json")
       }
    }).
    when("/sos_list/:id",{
       //设备报警信息列表
       controller: 'sos_list',
       templateUrl: 'view/device/sos_list.html',
       resolve : {
          async : getJSON(urlAddress + "/json/dev_set/sos_list.json")
       }
    }).
    when("/sos_sign",{
       //设备报警信息地图页
       controller: 'sos_sign',
       templateUrl: 'view/device/sos_sign.html',
       resolve : {
          async : getJSON(urlAddress + "/json/dev_set/sos_sign.json")
       }
    }).
    otherwise({
       redirectTo:'/'
    });
});

//用户信息管理的控制器
app.controller('users_sign',["$scope","async",function($scope,msg) {
     //用户总数
     $scope.number = msg.init.userNumber;
     //当前的页数
     $scope.nowPage = 1;
     // 最大的页数
     $scope.maxPage = 35;

     $scope.hasLastPage = true;
     $scope.pageN = $scope.nowPage;
     $scope.userDet = urlAddress + "/#/us_det"

     // 分页功能
     $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
     $scope.afterLi = $scope.pageA.afterLi;
     $scope.beforeLi = $scope.pageA.beforeLi;
     $scope.pageArr = $scope.pageA.arr;
     $scope.hasLastPage = $scope.pageA.hasLastPage;
     $("pages li").each(function() {
          var n = parseInt($(this).html());
     })

     // 设置初始的状态筛选条件和行数显示
     $scope.states = [
       {state : "在线", str: "在线"},
       {state : "离线", str: "离线"},
       {state : "全部", str: ""},
     ];
     //将获取的数据跟传给控制器
     $scope.opints = msg.data;
     if ($scope.opints.length < 1) {
         $scope.hasSign = true;
     } else {
         $scope.hasSign = false;
     }

     $scope.stateStr = $scope.states[2];
     $scope.lineNumbers = [10,15,20];
     $scope.lineNumber = $scope.lineNumbers[0];

     // 增加用户及相应的表单验证(大部分验证在HTML当中)
     $scope.addForm = true;
     $scope.addUser = function(bool) {
        $scope.addForm = bool;
     }
     $scope.idBool = function(bool) {
        $scope.userform.idBlur = bool;
     }
     $scope.devBool = function(bool) {
        $scope.userform.devBlur = bool;
     }
     $scope.addressBool = function(bool) {
        $scope.userform.addressBlur = bool;
     }
     $scope.accBool = function(bool) {
        $scope.userform.accBlur = bool;
     }

     //删除用户
     $scope.delUser = function() {
        // 获取所有被选中的元素及其对应的用户ID
        var delID = [];
        $("table td input").each(function() {
           if ($(this).prop("checked")) {
              delID.push($(this).parents("tr").attr("userID"));
           };
        })
         if(delID.length == 0) {
           alert("你没有选择任何用户");
         } else {
          console.log(delID);
            // window.location.reload();
         }
      }

      // 全选效果以及反选
      allChecked();

      //设置导航栏中当前页面的背景色
      navTitClass($("nav .users_sign").parent().eq(0));
}])

//手表信息管理的控制器
app.controller('watch_msg',["$scope","async",function($scope,msg) {
     //设备总数
     $scope.number = 3227;
     //当前的页数
     $scope.nowPage = 1;
     // 最大的页数
     $scope.maxPage = 35;

     $scope.hasLastPage = true;
     $scope.pageN = $scope.nowPage;
     $scope.usUrl = urlAddress + "/#/dev_set"

     // 分页功能
     $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
     $scope.afterLi = $scope.pageA.afterLi;
     $scope.beforeLi = $scope.pageA.beforeLi;
     $scope.pageArr = $scope.pageA.arr;
     $scope.hasLastPage = $scope.pageA.hasLastPage;
     $("pages li").each(function() {
          var n = parseInt($(this).html());
     })

     // 设置初始的状态筛选条件和行数显示
     $scope.states = [
       {state : "在线", str: "在线"},
       {state : "离线", str: "离线"},
       {state : "全部", str: ""},
     ]
     $scope.stateStr = $scope.states[2];
     $scope.lineNumbers = [10,15,20];
     $scope.lineNumber = $scope.lineNumbers[0];

     //将获取的数据跟传给控制器
     $scope.opints = msg;
     if ($scope.opints.length < 1) {
         $scope.hasSign = true;
     } else {
         $scope.hasSign = false;
     }

     // 增加用户及相应的表单验证(大部分验证在HTML当中)
     $scope.addForm = true;
     $scope.addUser = function(bool) {
        $scope.addForm = bool;
     }
     $scope.idBool = function(bool) {
        $scope.userform.idBlur = bool;
     }
     $scope.devBool = function(bool) {
        $scope.userform.devBlur = bool;
     }
     $scope.addressBool = function(bool) {
        $scope.userform.addressBlur = bool;
     }
     $scope.accBool = function(bool) {
        $scope.userform.accBlur = bool;
     }

     //删除用户
     $scope.delUser = function() {
        // 获取所有被选中的元素及其对应的用户ID
        var delID = [];
        $("table td input").each(function() {
           if ($(this).prop("checked")) {
              delID.push($(this).parents("tr").attr("userID"));
           };
        })
         if(delID.length == 0) {
           alert("你没有选择任何设备");
         } else {
          console.log(delID);
            // window.location.reload();
         }
     }

      // 全选效果以及反选
      allChecked();

      //设置导航栏中当前页面的背景色
      navTitClass($("nav .watch_msg").parent().eq(0));
}])

//用户意见反馈控制器
app.controller('users_opi',["$scope","async",function($scope,msg) {
     //用户总数
     $scope.number = msg.init.userNumber;
     //当前的页数
     $scope.nowPage = 1;
     // 最大的页数
     $scope.maxPage = 8;

     $scope.hasLastPage = true;
     $scope.pageN = $scope.nowPage;

     // 分页功能
     $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
     $scope.afterLi = $scope.pageA.afterLi;
     $scope.beforeLi = $scope.pageA.beforeLi;
     $scope.pageArr = $scope.pageA.arr;
     $scope.hasLastPage = $scope.pageA.hasLastPage;
     $("pages li").each(function() {
          var n = parseInt($(this).html());
     })

     //将获取的数据跟传给控制器
     $scope.opints = msg.data;
     if ($scope.opints.length < 1) {
         $scope.hasSign = true;
     } else {
         $scope.hasSign = false;
     }

     //控制行数
     $scope.lineNumbers = [10,15,20];
     $scope.lineNumber = $scope.lineNumbers[0];

      //删除信息
      $scope.delUser = function() {
          // 获取所有被选中的元素及其对应的ID
          var delID = [];
          $("table td input").each(function() {
             if ($(this).prop("checked")) {
                delID.push($(this).parents("tr").attr("userID"));
             };
          })
           if(delID.length == 0) {
             alert("你没有选择任何消息");
           } else {
               console.log(delID);
              // window.location.reload();
           }
        }

        // 全选效果以及反选
        allChecked();

        //设置导航栏中当前页面的背景色
        navTitClass($("nav .users_opi").parent().eq(0));
}])